package utils

import (
	"bufio"
	// "fmt"
	"strings"
	// "io/ioutil"
	"log"
	"os"
)

type Properties struct {
	filePath string
	entities map[string]string
	size     int
}

func (p *Properties) get(key string) string {
	return p.entities[key]
}

func LoadProperties(filePath string) Properties {
	var err error
	// var buf []byte
	var configfile *os.File
	configfile, err = os.Open(filePath)
	prop := Properties{}
	if err != nil {
		log.Fatal(err)
	}
	defer configfile.Close()

	scanner := bufio.NewScanner(configfile)
	data := make(map[string]string)
	for scanner.Scan() {
		_str := strings.TrimSpace(scanner.Text())
		if len(_str) > 0 && string(_str[0]) != "#" {
			sa := strings.Split(_str, "=")
			data[strings.TrimSpace(sa[0])] = strings.TrimSpace(sa[1])
		}

	}
	prop.entities = data

	if err := scanner.Err(); err != nil {
		log.Fatal(err)
	}
	return prop
}
